//
//  MSGameToolBar.m
//  MagicSword
//
//  Created by Netease on 15/11/24.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import "MSGameToolBar.h"

@implementation MSGameToolBar {
    SKSpriteNode *_infoButton;
    SKSpriteNode *_backButton;
}

- (id)init {
    self = [super initWithColor:UIColorFromRGBA(0xffffff, 0.) size:CGSizeMake(150, 50)];
    if (self) {
        [self initSubNodes];
    }
    return self;
}

- (void)initSubNodes {
    _infoButton = [SKSpriteNode spriteNodeWithImageNamed:@"game_info"];
    _infoButton.size = CGSizeMake(35, 35);
    _infoButton.position = CGPointMake(-30, 0);
    _infoButton.name = NodeName_HeroInfoButtonNode;
    [self addChild:_infoButton];
    
    _backButton = [SKSpriteNode spriteNodeWithImageNamed:@"game_back"];
    _backButton.size = CGSizeMake(35, 35);
    _backButton.position = CGPointMake(30, 0);
    _backButton.name = NodeName_HeroBackButtonNode;
    [self addChild:_backButton];
}

- (void)setHidden:(BOOL)hidden withAnimated:(BOOL)animated {
    if (hidden == NO) {
        [self setHidden:hidden];
    }
    
    if (animated) {
        if (!hidden) {
            [_infoButton runAction:[SKAction moveToX:-30 duration:0.2]];
            [_backButton runAction:[SKAction moveToX:30 duration:0.3]];
        } else {
            _infoButton.position = CGPointMake(-30, 0);
            [_infoButton runAction:[SKAction moveToX:80 duration:0.3] completion:^{
                [self setHidden:hidden];
            }];
            
            _backButton.position = CGPointMake(30, 0);
            [_backButton runAction:[SKAction moveToX:150 duration:0.2]];
        }
    }
    
}

@end
